<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id
 * @property int $main_id 主体用户id    访问人
 * @property int $guest_id 客体用户id  被访问人
 * @property int $time 访问时间
 * @property int $is_read 是否已读 1是 0否
 */
class VisitList extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'tb_visit_list';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'main_id' => 'integer', 'guest_id' => 'integer', 'time' => 'integer', 'is_read' => 'integer'];


    /**
     * Note - 获取未读的来访记录数量
     * DateTime 2024/8/15 12:03
     * User Admin
     * @param $uid
     * @return int
     */
    public static function getNotReadVisitCount($uid)
    {
        // $sql="select count(id) count_num from ".$this->tableV." where guest_id=? and is_read=?";
        // $pd = $this->createCommand($sql);
        // $pd->execute([$uid,0]);
        // $result = $pd->fetch(PDO::FETCH_ASSOC);
        // return $result['count_num']??0;
        return self::query()->where('guest_id', $uid)->where('is_read', 0)->count();
    }

}
